﻿@using MyBlog2.Models
@using MyBlog2.ViewModels
@model List<MyBlog2.Models.Article>

@{
    Layout = "_AdminLayout";
    ViewData["Title"] = "文章管理";
    var query = ViewBag.queryModel as ArticleQueryViewModel;

    var pagecount = Convert.ToInt32(ViewBag.pageCount);     //总页数
    var pageindex = Convert.ToInt32(ViewBag.pageIndex);     //主页页码
    var pagestart = pageindex - 2 > 0 ? pageindex - 2 : 1;      //设置开始页码，（共显示5个页码）
    var pageend = pageindex + 2 > pagecount ? pagecount : pagestart + 4;    //设置结束页码
}

<h1>文章管理</h1>
<br />

<!-- 表格 -->
<div class="table-responsive">
    <table class="table table-bordered table-hover">
        <thead class="thead-light">
            <tr>
                <th scope="col">序号</th>
                <th scope="col">标题</th>
                <th scope="col">类型</th>
                <th scope="col">是否发布</th>
                <th scope="col">更新时间</th>
                <th scope="col">操作</th>
            </tr>
        </thead>
        <tbody>
            @for (int i = 0; i < Model.Count; i++)
            {
                <tr>
                    <th scope="row">@(i+1)</th>
                    <td>@Model[i].Title</td>
                    <td>@Model[i].ArticleClassify.Name</td>
                    <td>@(Model[i].Published ? "是" : "否")</td>
                    <td>@Model[i].UpdateTime</td>
                    <td>
                        <a class="btn btn-info" asp-route="EditArticle" asp-route-id="@Model[i].Id">编辑</a>

                        @*<a class="btn btn-info" asp-area="Admin" asp-controller="AdminManage" asp-action="EditArticle" asp-route-id="@Model[i].Id">编辑</a>*@

                        <a class="btn btn-danger" asp-route="DeleteArticle" asp-route-id="@Model[i].Id">删除</a>

                        @*<a class="btn btn-danger" asp-area="Admin" asp-controller="AdminManage" asp-action="DeleteArticle" asp-route-id="@Model[i].Id">删除</a>*@
                    </td>
                </tr>
            }
        </tbody>
        <caption>
            <nav aria-label="Page navigation">
                <ul class="pagination">
                    <li class="@(pageindex == 1 ? "page-item disabled" : "page-item")">
                        <a class="page-link" aria-label="Previous" asp-route="ArticleManage" asp-route-pageIndex="@(pageindex == 1 ? 1 : pageindex - 1)">
                            <span aria-hidden="true">&laquo;</span>
                        </a>
                    </li>
                    @for (int i = pagestart; i <= pageend; i++)
                    {
                        <li class="@(pageindex == i ? "page-item active" : "page-item")"><a class="page-link" asp-route="ArticleManage" asp-route-pageIndex="@i">@i</a></li>
                    }
                    <li class="@(pageindex == pagecount ? "page-item disabled" : "page-item")">
                        <a class="page-link" aria-label="Next" asp-route="ArticleManage" asp-route-pageIndex="@(pageindex == pagecount ? pagecount : pageindex + 1)">
                            <span aria-hidden="true">&raquo;</span>
                        </a>
                    </li>
                </ul>
            </nav>
            
            <a class="btn btn-primary" style="float: right;" asp-route="AddArticle">添加</a>
        </caption>
    </table>
</div>